import { get } from '@/utils/request'
import type { Suggestion, SearchResults } from '@/types/data'

enum API {
  getSuggestion = '/suggestion', //获取文章搜索建议
  getSearchResults = '/search' //获取搜索结果
}

export default class DataServe {
  // 获取文章搜索建议
  static getSuggestion(data: { q: string }) {
    return get<{ options: Suggestion }>(API.getSuggestion, { params: data })
  }
  //获取搜索结果
  static getSearchResults({ q, page, per_page = 10 }: { q: string; page: number; per_page?: number }) {
    return get<SearchResults>(API.getSearchResults, {
      params: { q: q, page: page, per_page: per_page }
    })
  }
}
